/**
 * @param {number[]} nums
 * @param {number} k
 * @return {void} Do not return anything, modify nums in-place instead.
 */
var rotate = function (nums, k) {

  k = k % nums.length
  if (k == 0) return nums
  reverse(nums, 0, nums.length - 1)
  reverse(nums, 0, k)
  reverse(nums, k+1, nums.length - 1)

  function reverse(arr, start, end) {
    while (start <= end) {
      [arr[start], arr[end]] = [arr[end], arr[start]];
      start++
      end--
    }
  }

  return nums
};